package util

import (
	"RoccBlog/global"
	"github.com/golang-jwt/jwt/v5"
	"time"
)

func ParseToken(token string) (jwt.Claims, error) {
	parse, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
		return []byte(global.Config.Jwt.Security), nil
	})

	if err != nil {
		return nil, err
	}

	return parse.Claims, nil
}

func GeneratorToken(sub string) (string, error) {
	return jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"sub": sub,
		"iss": "dpengchen@163.com",
		"iat": float64(time.Now().UnixMilli()),
	}).SignedString([]byte(global.Config.Jwt.Security))
}
